<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateRefundStream extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('refund_stream', function (Blueprint $table) {
            $table->char('refundNo', 32)->default('')->comment("我方 唯一退款流水号");
            $table->char('payNo', 32)->default('')->comment('原我方支付订单流水号');
            $table->char('thirdRefundNo', 32)->default('')->comment("三方 唯一退款流水号");

            $table->unsignedTinyInteger('refundChannel')->default(0)->comment("退款渠道 1支付宝 2微信 3现金");
            $table->unsignedTinyInteger('refundType')->default(0)->comment("退款类型 0无 1全额退 2部分退");
            $table->unsignedInteger('refundPrice')->default(0)->comment("退款金额");
            $table->unsignedTinyInteger('refundStatus')->default(0)->comment("退款状态 0无 1退款中 2退款成功 3退款失败");
            $table->unsignedInteger('refundSuccessTime')->default(0)->comment("退款成功时间");

            // 统一表字段
            $table->integer('createdAt')->default(0)->comment('创建时间');
            $table->integer('createdByUid')->default(0)->comment('创建人');
            $table->integer('updatedAt')->default(0)->comment('修改时间');
            $table->integer('updatedByUid')->default(0)->comment('修改人');

            // 索引部分
            $table->primary('refundNo');
            $table->index('payNo', 'idx_payNo');
            $table->index('thirdRefundNo', 'idx_thirdRefundNo');
            $table->index('createdAt', 'idx_createdAt');

            $table->collation = 'utf8mb4_general_ci';
        });

        $prefix = config('other.DB_PREFIX', '');
        \Illuminate\Support\Facades\DB::statement("ALTER TABLE `{$prefix}refund_stream` COMMENT = '退款流水表'"); //表注释
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('refund_stream');
    }
}
